package rothag.views.gamestep.develop;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import javax.swing.JComponent;
import javax.swing.TransferHandler;

/**
 *
 * @author gulian
 */
public class ListTransferHandler extends TransferHandler {

    private DeveloppementJPanel developpementJPanel;

    /**
     * We only support importing strings.
     */
    ListTransferHandler(DeveloppementJPanel developpementJPanel) {
        super();
        this.developpementJPanel = developpementJPanel;
    }

    @Override
    public boolean canImport(TransferHandler.TransferSupport info) {
        // Check for String flavor
        if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            return false;
        }
        return true;
    }

    /**
     * Bundle up the selected items in a single list for export.
     * Each line is separated by a newline.
     */
    @Override
    protected Transferable createTransferable(JComponent c) {
        return new StringSelection("");
    }

    @Override
    public int getSourceActions(JComponent c) {
        return TransferHandler.COPY_OR_MOVE;
    }

    @Override
    public boolean importData(TransferHandler.TransferSupport info) {
        developpementJPanel.acheterDeveloppementSelectionne();
        return true;
    }

    @Override
    protected void exportDone(JComponent c, Transferable data, int action) {
    }
}
